package com.bjpowernode.controller;

import com.bjpowernode.beans.DictionaryType;
import com.bjpowernode.beans.DictionaryValue;
import com.bjpowernode.dto.ResultDTO;
import com.bjpowernode.exception.MyException;
import com.bjpowernode.services.DictionaryTypeServices;
import com.bjpowernode.services.DictionaryValueServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/DictionaryValue")
public class DictionaryValueController {
    @Autowired
    DictionaryValueServices dictionaryValueServices;
    @RequestMapping("getAll.action")
    public ResultDTO getAll(){
        ResultDTO resultDTO=new ResultDTO();
        ArrayList<DictionaryValue> all = dictionaryValueServices.getAll();
        resultDTO.setResult(true);
        resultDTO.setMess("查询成功");
        resultDTO.setData(all);
        return resultDTO;
    }
    @RequestMapping("del.action")
    public ResultDTO del(String  id) throws MyException {
        ResultDTO resultDTO=new ResultDTO();
        dictionaryValueServices.del(id);
        resultDTO.setResult(true);
        resultDTO.setMess("删除成功");
        return resultDTO;
    }

    @RequestMapping("add.action")
    public ResultDTO add(DictionaryValue dictionaryValue) throws MyException {
        ResultDTO resultDTO=new ResultDTO();
        dictionaryValueServices.add(dictionaryValue);
        resultDTO.setResult(true);
        resultDTO.setMess("添加成功");
        return resultDTO;
    }

    @RequestMapping(value = "editBefore.action")
    public ResultDTO get(String  id) throws MyException {
        ResultDTO resultDTO=new ResultDTO();
        DictionaryValue dictionaryValue = dictionaryValueServices.get(id);
        resultDTO.setResult(true);
        resultDTO.setMess("按照ID查询成功");
        resultDTO.setData(dictionaryValue);
        return resultDTO;
    }

    @RequestMapping("edit.action")
    public ResultDTO edit(DictionaryValue dictionaryValue) throws MyException {
        ResultDTO resultDTO=new ResultDTO();
        dictionaryValueServices.edit(dictionaryValue);
        resultDTO.setResult(true);
        resultDTO.setMess("修改成功");
        return resultDTO;
    }

}
